home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / dev / e / AP-examples.lha / AP-examples / AP-ProNET-C.e < prev    next >
Encoding:
Text File  |  2002-04-27  |  8.6 KB  |  289 lines

  1.  
  2. /* Example of using AWNPipe to create a reaction gui in E, by Dave Norris */
  3.  
  4. ->MODULE none needed
  5.  
  6. DEF pipefile,small,instring[10]:LIST,mainpage,clientpage,close,startinfo,pipereaderror,
  7.     in0[100]:STRING,in1[100]:STRING,in2[100]:STRING,in3[100]:STRING,in4[100]:STRING,
  8.     in5[100]:STRING,in6[100]:STRING,in7[100]:STRING,in8[100]:STRING,in9[100]:STRING,
  9.     str_spaces[10]:ARRAY OF INT,unitgadstr[200]:STRING,tbuffer[200]:STRING
  10.  
  11.      /*************  startup page  *************/
  12.  
  13. DEF ss0[80]:STRING,ss1[80]:STRING,ss2[80]:STRING,ss3[80]:STRING,ss4[80]:STRING,ss5[80]:STRING,
  14.     messagestr[9]:LIST,mtstr,startuplist
  15.  
  16.      /*************  pipe strings  *************/
  17.  
  18. DEF layout,layoutv,layoutbj,labelunit,space,le
  19.  
  20. CONST DETATCH=0,ATTACH=1
  21.  
  22. PROC main()
  23.   close:=FALSE   -> set to false in DEF's
  24.   setdefaults()
  25.   buildgui()
  26.   WHILE close=FALSE
  27.     getline()
  28. ->    PrintF('getline() got=\s.\s.\s.\s.\s\n',in0,in1,in2,in3,in4)
  29.     IF StrCmp('iconify',in0)
  30.       IF small=FALSE
  31.         topipe('id 0 s 32\n')  -> iconify
  32.         small:=TRUE
  33.       ELSE
  34.         topipe('id 0 s 64\n')  -> uniconify
  35.         small:=FALSE
  36.       ENDIF
  37.     ELSEIF StrCmp('close',in0)
  38.       close:=TRUE
  39.     ENDIF
  40.     topipe('con\n')       -> tell pipe there's no more modify commands, we want event
  41.   ENDWHILE
  42.   Close(pipefile)
  43.   IF pipereaderror THEN PrintF('\n Sorry, had to close down the gui,'+
  44.                                '\n received a read error from the pipe.\n')
  45. ENDPROC
  46.  
  47. PROC startupmessage()            -> put intro message on startup page
  48.   DEF x
  49.   attachedlist(startuplist,mainpage,DETATCH)
  50.   FOR x:=0 TO 7
  51.     addnodebuffer(startuplist,messagestr[x])
  52.   ENDFOR
  53.   attachedlist(startuplist,mainpage,ATTACH)
  54. ENDPROC
  55.  
  56. PROC addnodebuffer(id,text)                           -> add node to list
  57.   StringF(tbuffer,'id \d addnode gt="\s"\n',id,text)
  58. ENDPROC topipe(tbuffer)                               -> returns gadget id
  59.  
  60. PROC attachedlist(list,page,switch)
  61.   StringF(tbuffer,'id \d page \d list=\d\n',list,page,switch)
  62.   topipe(tbuffer)                       -> detach/attach list
  63. ENDPROC
  64.  
  65.  
  66.       /*********************************** GUI **********************************/
  67.  
  68.  
  69. PROC buildgui()
  70. DEF layoutmainpage[30]:STRING,layoutclientpage[30]:STRING
  71.  
  72.   pipefile:=Open('awnpipe:ProNET-C/xc',OLDFILE) ->wcon:300//200/200/PipeEvents
  73.   topipe('" ProNET-Control 1.0" m defg ig it="ProNET-C" ii="ProNET-Control" a cs\n')
  74.   mainpage:=topipe('clicktab ctl " Startup| Server| Client"\n')
  75.  
  76.       /************************  Start page  *********************/
  77.  
  78.   StringF(layoutmainpage,'layout b 0 so si page \d\n',mainpage) -> for tabs
  79.  
  80.   topipe(layoutmainpage)
  81.     topipe(layoutv)
  82.       startuplist:=topipe('listbrowser ro minh=120\n') ->minw 500 minh=140
  83.       topipe('browsernode gt " "\n')            -> put in text after window opens
  84.       topipe(space)
  85.       topipe(layout)
  86.         topipe(space)
  87.         topipe('layout gt=" Startup Prefs " b 3 so si v\n')
  88.           topipe(space)
  89.           topipe(layout)
  90.             topipe(space)
  91.             topipe('chooser pu cl " Open Window | Iconfiy " s=0 weiw=0\n')
  92.             topipe('button gt=" Snapshot Window " weih=0  weiw=0\n')
  93.             topipe(space)
  94.           topipe(le)
  95.           topipe(space)
  96.         topipe(le)
  97.         topipe(space)
  98.       topipe(le)
  99.       topipe(space)
  100.     topipe(le)
  101.   topipe(le)
  102.  
  103.       /***********************  End Start page *******************/
  104.  
  105.  
  106.       /************************  Server  *********************/
  107.  
  108.   topipe(layoutmainpage)
  109.     topipe(layoutv)
  110.       topipe('listbrowser lbl "  Click on a unit to activate it " minh 70 st\n') -> minw 550->350
  111.       topipe('browsernode gt " .config file not yet loaded"\n')
  112.       topipe('button gt=" Load units from Devs:ProNET/.config " weih 0 cj\n')
  113.       topipe('listbrowser lbl "  Units activated " ro minh=70 multi st\n') -> minw 550 weiw
  114.       topipe('browsernode gt " None"\n')
  115.       topipe('button gt " Stop ProNET-Server on all units " weih 0 cj\n') -> weiw 1
  116.     topipe(le)
  117.   topipe(le)
  118.  
  119.       /**********************  End Server  *********************/
  120.  
  121.  
  122.   StringF(tbuffer,'layout b 0 page \d\n',mainpage)
  123.  
  124.   topipe(tbuffer)
  125.     clientpage:=topipe('clicktab ctl " Mount| Page |  Talk "\n')
  126.   topipe(le)
  127.  
  128.  
  129.       /************************  Client  *********************/
  130.  
  131.   StringF(layoutclientpage,'layout b 0 so si page \d\n',clientpage)
  132.  
  133.   topipe(layoutclientpage)
  134.     topipe(layoutv)
  135.       topipe('listbrowser lbl " Status | Local Name | Remote Name | Volume Name | Unique " st v\n') ->minw 500 minh=140
  136.       topipe('browsernode gt "||||"\n')
  137.       StringF(tbuffer,'string gt="\s" ro cj\n',startinfo)
  138.       topipe(tbuffer)
  139.       topipe('layout b 0 si so bj weih=0\n')
  140.         topipe('button gt " Scan server " weih=0\n')
  141.         topipe(space)
  142.         topipe(labelunit)
  143.         topipe(unitgadstr)
  144.         topipe(space)
  145.         topipe('label gt="Local Name:"\n')
  146.         topipe('string cj minw=120 maxc=20 dis=1\n')
  147.       topipe(le)
  148.     topipe(le)
  149.   topipe(le)
  150.  
  151.      /***********************  End Client  ********************/
  152.  
  153.  
  154.       /************************  page  **************************/
  155.  
  156.   topipe(layoutclientpage)
  157.     topipe(layoutv)
  158.       topipe(space)
  159.       topipe('layout gt=" Send message to server " b 3 so si v\n')
  160.         topipe(space)
  161.         topipe(layout)
  162.           topipe(space)
  163.           topipe(layoutv)
  164.             topipe('label gt=" Message:"\n')
  165.             topipe('string lj minw=324 maxc=70\n')
  166.           topipe(le)
  167.           topipe(space)
  168.         topipe(le)
  169.         topipe(space)
  170.         topipe(layoutbj)
  171.           topipe(space)
  172.           topipe(labelunit)
  173.           topipe(unitgadstr)
  174.           topipe(space)
  175.           topipe('button gt " Send message " weih 0 weiw 0\n')
  176.           topipe(space)
  177.         topipe(le)
  178.         topipe(space)
  179.       topipe(le)
  180.       topipe(space)
  181.     topipe(le)
  182.   topipe(le)
  183.  
  184.      /***********************  End page  ************************/
  185.  
  186.  
  187.      /************************  talk  **************************/
  188.  
  189.   topipe(layoutclientpage)
  190.     topipe(space)
  191.     topipe(layoutv)
  192.     topipe(space)
  193.     topipe('layout gt=" Chat with server " b 3 so si v\n')
  194.       topipe(space)
  195.       topipe(layoutbj)
  196.         topipe(space)
  197.         topipe('button gt " Start Pronet-talk on both machines " cj weih=0 weiw=0\n')
  198.         topipe(space)
  199.       topipe(le)
  200.       topipe(layoutbj)
  201.         topipe(space)
  202.         topipe(labelunit)
  203.         topipe(unitgadstr)
  204.         topipe(space)
  205.       topipe(le)
  206.       topipe(space)
  207.     topipe(le)
  208.     topipe(space)
  209.     topipe(le)
  210.     topipe(space)
  211.   topipe(le)
  212.  
  213.  
  214.      /***********************  End talk  ************************/
  215.  
  216.  
  217.   topipe('open\n')      -> open the window
  218.   startupmessage()       -> put text in startup listbrowser
  219.   topipe('con\n')       -> start listening to events from the pipe
  220. ENDPROC
  221.  
  222.      /********************************** End GUI ********************************/
  223.  
  224.  
  225. PROC setdefaults()    -> ******* put here to unclutter main() *******
  226.  
  227.   instring:=[in0,in1,in2,in3,in4,in5,in6,in7,in8,in9]:LONG
  228.   startinfo:='Start the remote server before attempting to scan it'
  229.  
  230.   mtstr:=' '
  231.  
  232.   ss0:='  Example of using AWNPipe in E,'
  233.   ss1:='  to produce a reaction gui.'
  234.   ss2:='  As you can see from this programs size,'
  235.   ss3:='  using AWNPipe can make your program code smaller.'
  236.   ss4:='  It also lets you write the gui code faster,'
  237.   ss5:='  leaving you to concentrate on the main code.'
  238.  
  239.   messagestr:=[ss0,ss1,mtstr,ss2,ss3,mtstr,ss4,ss5]:LONG
  240.  
  241.   layout:='layout b 0 so si\n'
  242.   layoutv:='layout b 0 v so si\n'
  243.   layoutbj:='layout b 0 so si bj\n'
  244.   labelunit:='label gt="Unit:"\n'
  245.   space:='space\n'
  246.   le:='le\n'
  247.  
  248.   StringF(unitgadstr,'chooser pu cl " 0 | 1 | 2 " maxn=3 weiw=0\n')
  249.  
  250. ENDPROC
  251.  
  252. PROC getline()     -> loops until all data seperated by spaces is collected
  253.   DEF input[1024]:STRING
  254.   IF ReadStr(pipefile,input)<>-1     -> returns -1 if error or EOF encounted
  255. ->    PrintF('incomming=\s\n',input)
  256.     cutup_str(input)
  257.   ENDIF
  258. ENDPROC
  259.  
  260. PROC cutup_str(input)
  261.   DEF space,x,gap
  262.   x:=0
  263.   WHILE (space:=InStr(input,' '))<>-1
  264.     StrCopy(instring[x],input,space)
  265.     MidStr(input,input,space+1)
  266.     gap:=StrLen(input)
  267.     input:=TrimStr(input)
  268.     INC x
  269.     str_spaces[x]:=gap-StrLen(input)
  270.   ENDWHILE
  271.   StrCopy(instring[x],input)
  272. ENDPROC
  273.  
  274. PROC topipe(data)
  275.   DEF res,input[10]:STRING
  276.   Fputs(pipefile,data)             -> used instead of VfPrintf()
  277. ->  PrintF('Data Sent=\s.',data)
  278.   IF ReadStr(pipefile,input)<>-1     -> returns -1 if error or EOF encounted
  279. ->    PrintF('Data comming back=\s.\n\n',input)
  280.     IF StrCmp(input,'ok',2)
  281.       IF StrLen(input)>2 THEN res:=RightStr(input,input,(StrLen(input)-3))
  282.     ENDIF
  283.   ELSE
  284. ->    PrintF('Error or EOF from ReadStr(pipef,input)\n')
  285.     pipereaderror:=TRUE
  286.     close:=TRUE
  287.   ENDIF
  288. ENDPROC Val(res)
  289.